<? FoundryView::includeTpl( 'adminMain:header' ) ?>

<script type="text/javascript">
	function checkUserForm() {
		var p1 = document.getElementById( 'userPass1' );
		var p2 = document.getElementById( 'userPass2' );
		
		if( p1.value.length > 1 && p2.value.length > 1 ) {
			
			if( p1.value != p2.value ) {
				alert( 'Your passwords do not match!' );
				p1.focus();
				return false;
			}
			
		}
		
		return true;
	}
</script>

<div id="mainContent">
	<h2>Users</h2>

	<a href="<?=FoundryView::helperLinkTo( 'userAdmin/edit' )?>" class="actionLink">
		<img src="<?=Foundry::config('webpath')?>/images/admin/add.png" />
		new user</a>
	<span id="actionMessage"></span>
	
	<div class="actionForm">
		<form method="post" name="userForm" action="<?=FoundryView::helperLinkTo('userAdmin/edit')?>/<?=$this->data['user']->uid?>" onsubmit="return checkUserForm()">

		<div class="cellLeft">
	
			<input type="hidden" name="k" value="<?=$this->data['key']?>" />
			<label for="userUsername">Username</label>
			<? if( $this->data['user']->username ) : ?>
				<b><?=$this->data['user']->username?></b><p />
			<? else : ?>
				<input type="text" name="userUsername" value="" /><p />
			<? endif ?>

			<label for="userGroup">Group</label>
			<select name="userGroupID">
			<?php
			
				$mGroup = FoundryController::model( 'group' );
				$groups = $mGroup->find( 'order by *name' );
				foreach( $groups as $group ) {
					echo '<option value="'.$group->uid.'"';
					
					if( $group->uid == $this->data['user']->group_id ) {
						echo ' selected="selected"';
					}
					
					echo '>'.$group->name.'</option>';
				}
			?>
			</select><p />

			<label for="userFullname">Full Name</label>
			<input type="text" name="userFullname" value="<?=$this->data['user']->fullname?>" /><p />

			<label for="userFullname">Email Address</label>
			<input type="text" name="userEmail" value="<?=$this->data['user']->email?>" /><p />

			<div class="highlight">
				<label for="userPass1">New Password</label>
				<input type="password" name="userPass1" id="userPass1" value="" /><p />

				<label for="userPass2">Re-type New Password</label>
				<input type="password" name="userPass2" id="userPass2" value="" /><p />

			</div><p />

			<input type="submit" value="Save" />
			<a href="<?=FoundryView::helperLinkTo( 'userAdmin/' )?>" class="cancelLink">
				Cancel</a>
		</div>
		<div class="cellRight">

			

		</div>
		<br class="cellBottom" />
		
		</form>
	</div>	
	
</div>

<? FoundryView::includeTpl( 'adminMain:footer' ) ?>